<?php /* Smarty version 2.6.20, created on 2011-10-27 14:41:08
         compiled from _core/pagecommon/_mvc/_control/handlepageproducehistory.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/pagecommon/_mvc/_control/handlepageproducehistory.tpl', 54, false),)), $this); ?>
function HandlePageProduceHistory(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  
  this._customerId = (options && options.id) ? options.id : null;
  this._orderTrackId = (options && options.track) ? options.track : [];
  
  this._createElements();
};

HandlePageProduceHistory.prototype._createElements = function() {
  this._gui.results.appendChild(DOMUtils.getLoadingImage());
  this._loadData();
};

HandlePageProduceHistory.prototype._loadData = function() {
  this._customer = null;
  this._produces = null;
  this._retrieveCustomer();
  this._retrieveProduces();
};

HandlePageProduceHistory.prototype._verifyData = function() {
  if (this._customer && this._produces) {
    this._updateElements();
  }
};

HandlePageProduceHistory.prototype._retrieveCustomer = function() {
  var _self = this;
  if (this._customerId) {
    /*new RequestUtils()._read('customer', null, 'd.oid =' + this._customerId, null, null, null, null, function(result, params) { _self._customer = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                                _self._verifyData.call(_self);
                                                                                                                              }, null);
  */
  var args = '&oid=' + this._customerId; 
  new RequestUtils()._mysql('v1customer', args, function(result, params) { _self._customer = (result.data.length == 1) ? result.data[0] : null;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});   
  
  } else {
    this._customer = v1customer.instance();
    this._customer.createdDate = this._now;
    this._customer.sales = this._operator;
    this._verifyData();
  }
};

HandlePageProduceHistory.prototype._retrieveProduces = function(pos) {
  var _self = this;
  if (this._customerId) {
//    new RequestUtils()._read('produce', null, 'd.branch = \'<?php echo ((is_array($_tmp=@BRANCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
\' AND d.customerId = ' + this._customerId, null, null, null, null, function(result, params) { _self._produces = result.data;
//                                                                                                                                                                                                     _self._verifyData.call(_self);
//                                                                                                                                                                                                   }, { php: Constant.FACTORY + '/jsonread.php', pos: pos });

    var joins = '&events=1' + '&tracks=1';
    var args = '&c=d.branch = \'<?php echo ((is_array($_tmp=@BRANCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
\' AND d.customerId = ' + this._customerId + joins;
    new RequestUtils()._mysql('produce', args, function(result, params) { _self._produces = result.data;
                                                                          _self._parameters = result;
                                                                          _self._verifyData.call(_self);
                                                                        }, { php: Constant.FACTORY + '/customphp/produceread.php'});
  } else {
    this._produces = [];
  }
};

HandlePageProduceHistory.prototype._updateElements = function() {
  var table, tr, td, order = DlmanageUtils.order(this._customer.orders, this._orderTrackId), _self = this;
  DOMUtils.removeChildElements(this._gui.results);
  table = document.createElement('table');
  table.style.width = '900px';
  table.cellPadding = 0;
  table.cellSpacing = 0;
  this._gui.results.appendChild(table);
  
  if (this._produces.length == 0) {
    tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
    return;
  }
  /* 提取所有Produces */
  var produces = MiscUtils.find(this._produces, [{ attrs: ['orderTrackId'], value: order.trackId }, { attrs: ['_deleted'], value: undefined }]);
  
  op = MiscUtils.find(produces, [{ attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRECON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_MUSIC)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_REQUIREMENT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }], MiscUtils.disjunction);
  wp = MiscUtils.find(produces, [{ attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_PHOTOGRAPHER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_VIDEOGRAPHER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_MAKEUP)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_LIGHT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }], MiscUtils.disjunction);
  
  /* 提取所有产品流程 ,并且分类到套餐产品流程和附加产品流程 */
  gp = MiscUtils.find(produces, [{ attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEO)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEODVD)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_4X6)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_RETOUCH_MAGAZINE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_RETOUCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_COMMON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_ALBUM_DESIGN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }], MiscUtils.disjunction);
//  pp = MiscUtils.find(gp, [{ attrs: ['purchase', 'packageInc'], value: '', unequal: true }]);
//  ap = MiscUtils.find(gp, [{ attrs: ['purchase', 'packageInc'], value: '' }]);
  /* 提取所有产品 ,并且分类到套餐产品和附加产品 */
  purchases = MiscUtils.find(order.purchaseItems, [{ attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEO)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEODVD)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_4X6)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_RETOUCH_MAGAZINE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_RETOUCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_COMMON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_ALBUM_DESIGN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '' }], MiscUtils.disjunction);
//  p = MiscUtils.find(purchases, [{ attrs: ['packageInc'], value: '', unequal: true }]);
//  a = MiscUtils.find(purchases, [{ attrs: ['packageInc'], value: '' }]);

  for (var i = 0, il = produces.length; i < il; i++) {
    var produce = produces[i];
    tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.padding = '10px 0 0 0';
    new TableProduceHistory(td, produce, { user: this._operator, date: this._now, rest: purchases, callbackFunc: function(pos) { _self._retrieveProduces.call(_self, pos); }, produces: this._produces, purchases: order.purchaseItems, hidePrice: true, parent: order});
  }
  
  MiscUtils.sort(purchases, ['name']);
  DlmanageUtils.compare(purchases, gp);
  for (var i = 0, il = purchases.length; i < il; i++) {
    var purchase = purchases[i];
    if (purchase._added) {
      continue;
    }
    purchase.v2_events = [];
    tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.padding = '10px 0 0 0';
    new TableProduceHistory(td, purchase, { user: this._operator, date: this._now, rest: purchases, callbackFunc: function(pos) { _self._retrieveProduces.call(_self, pos); }, produces: this._produces, purchases: order.purchaseItems, noLog: true, parent: order});
  }
};